<template>
  <div>
    <FormTable :formData="formData"
               :columnData="columnData"
               :url="$api.integral_task_getlist"
               :editData="editData"
               :new_url="this.$api.integral_task_insert"
               :detail_url="this.$api.integral_task_info"
               :edit_url="this.$api.integral_task_save"
               :is_default_edit="true"
               label-width="140px"
               :pageConfig="pageConfig"></FormTable>
  </div>
</template>

<script>
export default {
  data () {
    return {
      formData: [
        {
          name: "task_title",
          label: "积分任务标题",
          value: "",
          type: "input",
        },
        {
          name: "display",
          label: "是否显示",
          value: '',
          type: "select",
          groups: [
            {
              label: '所有',
              value: ''
            },
            {
              label: '显示',
              value: 1
            },
            {
              label: '隐藏',
              value: 0
            },
          ]
        },
        {
          name: "type",
          label: "任务类型",
          value: '',
          type: "select",
          groups: [
            
          ]
        },
      ],
      columnData: [
        {
          prop: "integral_task_id",
          label: "id"
        },
        {
          prop: "task_title",
          label: "积分任务标题"
        },
        {
          prop: "task_desc",
          label: "积分任务介绍"
        },
        {
          prop: "icon_url",
          label: "积分图标",
          custom:true,
          type:'icon'
        },
        {
          prop: "task_url",
          label: "积分任务链接",
        },
        {
          prop: "type",
          label: "任务类型",
        },
        {
          prop: "display",
          label: "是否显示",
          custom: true,
          type: 'switch',
          url: this.$api.integral_task_status
        },
        {
          prop: "sort",
          label: "排序",
          custom: true,
          type: 'input',
          url: this.$api.integral_task_sort
        },
        {
          prop: 'btn_group',
          label: '操作',
          custom: true,
          type: 'btn_group',
          width:'200px',
          group: [
            {
              name: '编辑',
              type: 'edit',
              color: 'primary',
              detail_mark: 'integral_task_id',
            },
            {
              name: '删除',
              type: 'delete',
              color: 'danger',
              url: this.$api.integral_task_status
            }
          ]
        }
      ],
      editData: [
        {
          name:'integral_task_id',
          label:'积分任务id',
          value:'',
          type:'input',
          display:'none'
        },
        {
          name: "task_title",
          label: "积分任务标题",
          value: '',
          type: "input",
          rules:[
            { required: true, message: "请输入积分任务标题", trigger: "blur" },
          ]
        },
        {
          name: 'task_desc',
          label: '积分任务介绍',
          value: '',
          type: 'textarea',
          rules:[
            { required: true, message: "请输入积分任务介绍", trigger: "blur" },
          ]
        },
        {
          name: 'task_url',
          label: '积分任务链接',
          value: '',
          type: 'input',
          rules:[
            { required: true, message: "请输入积分任务链接", trigger: "blur" },
          ]
        },
        {
          name: 'type',
          label: '任务类型',
          value: '',
          type: 'select', 
          groups:[],
          sel_arr:['rule'],
          sel_rule:[
            {
              id:2,
              show_arr:['rule']
            }
          ]
        },
        {
          name: 'rule',
          label: '规则',
          value: '',
          type: 'editForm',
          width:'100%',
          config:{
            formData:[
              {
                name: "num",
                label: "试玩时间(秒)",
                value: '',
                type: "input",
              },
              {
                name: "integral",
                label: "所得积分",
                value: '',
                type: "input",
              },
            ]
          }
          // display:'none'
        },
        {
          name: 'sort',
          label: '排序',
          value: '',
          type: 'input',
        },
        {
          name: 'display',
          label: '是否显示',
          value: '',
          type: 'switch',
          config: {
            'active_value': '1',
            'inactive-value': '0'
          }
        },
        {
          name: 'icon_url',
          label: '积分图标',
          value: '',
          type: 'image_upload',
          width: '100%',
          config: {
            limit: 1,
            accept: ".jpg,.png,.bmp,.gif,.svg",
            fileList: []
            // is_icon:true
          },
          rules:[
            { required: true, message: "请添加积分图标", trigger: "blur" },
          ]
        },
      ],
      pageConfig: {
        page: 1,
        pagesize: 10,
      }
    };
  },
  created () {
    this.getCard();
  },
  methods: {
    getCard(){
      this.$req.get(this.$api.integral_task_getintegraltasktype).then(res => {
        let data = res.data;
        for (var i in data) {
          this.formData[2].groups.push({
            label: data[i].integral_task_type_name,
            value: data[i].integral_task_type_id,
          })

          this.editData[4].groups.push({
            label: data[i].integral_task_type_name,
            value: data[i].integral_task_type_id,
          })
        }
      })
    },
    handleSizeChange (e) {
      console.log(e);
    },
    handleCurrentChange (e) {
      console.log(e);
    },
    submit (e) {
      console.log(e);
    },
    reset (e) {
      console.log(e);
    }
  }
}
</script>

<style lang="scss" scoped>
</style>